//
// Created by shenbin on 2022/4/16.
// https://leetcode-cn.com/problems/move-zeroes/
//

#ifndef ALGORITHM_TRAINNING_C01_LC283_H
#define ALGORITHM_TRAINNING_C01_LC283_H

#include <vector>

using namespace std;

class LeetCode283 {
public:
    void moveZeroes(vector<int> &nums) {
        int n = 0;
        //保留顺序，存储非0数据；
        for (int = 0; i < nums.size(); i++) {
            if (nums[i] != 0) {
                nums[n] = nums[i];
                n++;
            }
        }
        //如果n小于数组的个数，那么尾部补0；
        while (n < nums.size()) {
            nums[n] = 0;
            n++;
        }

    }
};

#endif //ALGORITHM_TRAINNING_C01_LC283_H
